package week8th;

public class AVLTreeNode <T extends Comparable<T>>
{
    public int height;
    protected T node,element;
    protected AVLTreeNode<T> left;
    protected AVLTreeNode<T> right;

    public AVLTreeNode(T obj) {
        this.node = obj;
        this.left = null;
        this.right = null;
        this.height=0;

    }

    public AVLTreeNode(T element, AVLTreeNode<T> left, AVLTreeNode<T> right) {
        this.element = element;
        this.left = left;
        this.right = right;
        this.height = 0;
    }


    public boolean isLeaf() {
        if(left==null && right==null){
            return true;
        }else {
            return false;
        }
    }

    public T getElement() {
        return element;
    }

    public AVLTreeNode<T> getRight() {
        return right;
    }

    public AVLTreeNode<T> getLeft() {
        return left;
    }

    public void setElement(T element) {
        this.element = element;
    }

    public void setLeft(AVLTreeNode<T> left) {
        this.left = left;
    }

    public void setRight(AVLTreeNode<T> right) {
        this.right = right;
    }


    public int numChildren() {
        int children = 0;

        if (left != null)
            children = 1 + left.numChildren();

        if (right != null)
            children = children + 1 + right.numChildren();

        return children;
    }

}

